import { cloneDeep } from 'lodash'
// 深拷贝
export const CLONEDEEP = (data) => {
  return cloneDeep(data)
}
// 日期格式化
export const formatDate = (t, type = 0, day = 0) => {
  if (!t) return ''
  const add0 = function (m) { return m < 10 ? '0' + m : m }
  let time = t
  if (typeof (time) === 'string') {
    time = time.replace(/-/g, '/')
    time = new Date(time)
  }
  /* 天数增加 */
  if (day !== 0) {
    time = new Date(time.getTime() + 3600 * 24 * 1000 * day)
  }
  const y = time.getFullYear()
  const m = time.getMonth() + 1
  const d = time.getDate()
  const h = time.getHours()
  const mm = time.getMinutes()
  const s = time.getSeconds()
  const _date = y + '-' + add0(m) + '-' + add0(d)
  const _time = add0(h) + ':' + add0(mm) + ':' + add0(s)
  const _dateTime = y + '-' + add0(m) + '-' + add0(d) + ' ' + add0(h) + ':' + add0(mm) + ':' + add0(s)
  // if (k.slice(-8) === '00:00:00') k = k.slice(0, -9)
  if (type === 0) return _date
  if (type === 1) return _time
  if (type === 2) return _dateTime
  return _date
}
// datalist 转 二维数组 就是用于表格显示， [{},{}, ...] => [[],[], ...]
export const formatJson = (filterVal, jsonData) => {
  return jsonData.map(v => filterVal.map(j => v[j]))
}
